def eval_jsonlang(json_obj, env=None):
    """解释执行 JSONLang"""
    if env is None:
        env = {}
    if isinstance(json_obj, (int, float, bool)):
        return json_obj
    elif isinstance(json_obj, str):
        if json_obj in env:
            return env[json_obj]
        else:
            return json_obj  # 字符串字面量
    elif isinstance(json_obj, dict):
        if "let" in json_obj:
            new_env = env.copy()
            for binding in json_obj["let"]:
                new_env[binding["var"]] = eval_jsonlang(binding["value"], new_env)
            return eval_jsonlang(json_obj["body"], new_env)
        elif "lambda" in json_obj:
            return lambda *args: eval_jsonlang(
                json_obj["lambda"]["body"],
                {**env, **dict(zip(json_obj["lambda"]["params"], args))}
            )
        elif "if" in json_obj:
            cond = eval_jsonlang(json_obj["if"]["condition"], env)
            return eval_jsonlang(json_obj["if"]["then" if cond else "else"], env)
        elif "define" in json_obj:
            env[json_obj["define"]["name"]] = eval_jsonlang({
                "lambda": {
                    "params": json_obj["define"]["params"],
                    "body": json_obj["define"]["body"]
                }
            }, env)
            return None
        else:
            # 函数调用 {"func": [arg1, arg2]}
            func = next(iter(json_obj))
            args = [eval_jsonlang(arg, env) for arg in json_obj[func]]
            if func in env:
                return env[func](*args)
            elif func == "+":
                return sum(args)
            elif func == "*":
                return args[0] * args[1]
            elif func == "<=":
                return args[0] <= args[1]
            else:
                raise ValueError(f"Unknown function: {func}")
    else:
        raise ValueError(f"Unknown JSONLang object: {json_obj}")

# 示例：直接执行 JSONLang
jsonlang_code = {
  "define": {
    "name": "factorial",
    "params": ["n"],
    "body": {
      "if": {
        "condition": {"<=": ["n", 1]},
        "then": 1,
        "else": {"*": ["n", {"factorial": {"-": ["n", 1]}}]}
      }
    }
  },
  "factorial": [5]
}
result = eval_jsonlang(jsonlang_code)
print(result)  # 输出: 120
